package com.lz.gmall.common.utils;

import com.lz.gmall.cart.vo.UserAuthInfoVo;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 郭运龙
 * 工具类
 */
public class UserAuthUtil {

    public static UserAuthInfoVo getUserAuthInfo(){

        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();

        if (servletRequestAttributes!=null){
            HttpServletRequest request = servletRequestAttributes.getRequest();
            String userId = request.getHeader("userId");
            String userTempId = request.getHeader("userTempId");

            UserAuthInfoVo userAuthInfoVo = new UserAuthInfoVo();
            userAuthInfoVo.setUserId(userId);
            userAuthInfoVo.setUserTempId(userTempId);
            return userAuthInfoVo;
        }

        return null;
    }
}
